package com.lvandroid.transport.task;

public abstract class TaskInfo {

    public static final int TASK_TYPE_UNKNOWN = 0;
    public static final int TASK_TYPE_DOWNLOAD = 1;
    public static final int TASK_TYPE_UPLOAD = 2;

    //任务ID
    public long mTaskId;
    //上传/下载的url
    public String mTaskUrl;
    //任务对应文件的path，如果是上传，则对应本地文件路径，如果是下载，则对应本地存储的文件路径
    public String mFilePath;
    //当前任务进度，记录上传/下载了多少
    public long mCurrentTaskLength;
    //任务是否已完成
    public boolean mTaskComplete;
    //任务总进度
    public long mTotalTaskLength;
    //是否需要恢复
    public boolean mNeedResume;
    //当前任务百分比进度
    public float mPercent;
    //任务类型，下载/上传/未知
    public int mTaskType = TASK_TYPE_UNKNOWN;

    public int getTaskType() {
        return mTaskType;
    }

    public void setTaskType(int type) {
        mTaskType = type;
    }

    public String getTaskUrl() {
        return mTaskUrl;
    }

    public void setTaskUrl(String mTaskUrl) {
        this.mTaskUrl = mTaskUrl;
    }

    public String getFilePath() {
        return mFilePath;
    }

    public float getPercent() {
        return mPercent;
    }

    public void setPercent(float mPercent) {
        this.mPercent = mPercent;
    }

    public void setFilePath(String mFilePath) {
        this.mFilePath = mFilePath;
    }

    public long getCurrentTaskLength() {
        return mCurrentTaskLength;
    }

    public void setCurrentTaskLength(long mCurrentTaskLength) {
        this.mCurrentTaskLength = mCurrentTaskLength;
    }

    public boolean isTaskComplete() {
        return mTaskComplete;
    }

    public void setTaskComplete(boolean mTaskComplete) {
        this.mTaskComplete = mTaskComplete;
    }

    public long getTotalTaskLength() {
        return mTotalTaskLength;
    }

    public long getTaskId() {
        return mTaskId;
    }

    public void setTaskId(int mTaskId) {
        this.mTaskId = mTaskId;
    }

    public void setTotalTaskLength(long mTotalTaskLength) {
        this.mTotalTaskLength = mTotalTaskLength;
    }

    public boolean isNeedResume() {
        return mNeedResume;
    }

    public void setNeedResume(boolean mNeedResume) {
        this.mNeedResume = mNeedResume;
    }

    /**
     * 保存任务，具体由子类实现，可选择保存数据库/xml/sp等存储介质中
     * @return 是否保存成功
     */
    public abstract boolean saveTask();

    /**
     * 删除任务，从保存的介质中删除，并删除对应的本地文件（如果是下载任务，且需要）
     * @return
     */
    public abstract boolean deleteTask();

    /**
     * 获取文件MD5值
     * @return 任务对应文件的MD5值
     */
    public String getTaskFileMD5() {
        return null;
    }

    @Override
    public String toString() {
        return "TaskInfo{" +
                "mTaskId=" + mTaskId +
                ", mTaskUrl='" + mTaskUrl + '\'' +
                ", mFilePath='" + mFilePath + '\'' +
                ", mCurrentTaskLength=" + mCurrentTaskLength +
                ", mTaskComplete=" + mTaskComplete +
                ", mTotalTaskLength=" + mTotalTaskLength +
                ", mNeedResume=" + mNeedResume +
                '}';
    }
}
